﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inspired.Euler
{
    public static class Problem052
    {
        /// <summary>
        /// Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.
        /// </summary>
        [EulerProblem(52, Title = "Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.")]
        public static long Solve()
        {
            for(int i = 1; ; i++)
            {
                List<string> numbers = new List<string>()
                {
                    new string((i * 1).ToString().ToCharArray().OrderBy(c => c).ToArray()),
                    new string((i * 2).ToString().ToCharArray().OrderBy(c => c).ToArray()),
                    new string((i * 3).ToString().ToCharArray().OrderBy(c => c).ToArray()),
                    new string((i * 4).ToString().ToCharArray().OrderBy(c => c).ToArray()),
                    new string((i * 5).ToString().ToCharArray().OrderBy(c => c).ToArray()),
                    new string((i * 6).ToString().ToCharArray().OrderBy(c => c).ToArray())
                };

                string x = numbers[0];
                if(numbers.All(n => n == x))
                    return i;
            }
            return 0;
        }
    }
}
